
pkgname=krb5
pkgver=1.16.1
_pkgver=1.16
pkgrel=1
pkgdesc="The Kerberos network authentication system"
arch=('x86_64')
url="https://web.mit.edu/kerberos/"
license=('custom')
depends=('e2fsprogs' 'libldap' 'keyutils')
makedepends=('perl')
options=('!emptydirs')
backup=('etc/krb5.conf' 'var/lib/krb5kdc/kdc.conf')
source=("https://web.mit.edu/kerberos/dist/krb5/${_pkgver}/${pkgname}-${pkgver}.tar.gz"
        'krb5-config_LDFLAGS.patch'
        'krb5-kadmind.service'
        'krb5-kdc.service'
        'krb5-kpropd.service'
        'krb5-kpropd@.service'
        'krb5-kpropd.socket')
md5sums=('848e9b80d6aaaa798e3f3df24b83c407'
         'a1eb1629bef5427b18f521eff4de61b3'
         'd2c898d376ebe5c62b873da7cab0f7e7'
         'f0245d33083337f95654f4caf1d32f57'
         '3dddf2f79ef74c4e736711e41228ee91'
         'babefac221331f7131a29faac33cc5bc'
         '5b9cee689e4f8085d39ef4e05f1ddd9a')


build() {
   tar xf ${pkgname}-${pkgver}.tar.gz
   cd ${pkgname}-${pkgver}
   
   patch -p1 -i ${srcdir}/krb5-config_LDFLAGS.patch

   sed -i "/KRB5ROOT=/s/\/local//" src/util/ac_check_krb5.m4
   
   cd src

   export CFLAGS+=" -fPIC -fno-strict-aliasing -fstack-protector-all"
   export CPPFLAGS+=" -I/usr/include/et"
   ./configure --prefix=/usr \
               --sysconfdir=/etc \
               --localstatedir=/var/lib \
               --enable-shared \
               --with-system-et \
               --with-system-ss \
               --disable-rpath \
               --without-tcl \
               --enable-dns-for-realm \
               --with-ldap \
               --without-system-verto
   make
}

package() {
   cd ${pkgname}-${pkgver}/src
   make DESTDIR=${pkgdir} EXAMPLEDIR="/usr/share/doc/${pkgname}/examples" install

   # KDC config file
   install -dm 755 ${pkgdir}/var/lib/krb5kdc
   install -pm 644 config-files/kdc.conf ${pkgdir}/var/lib/krb5kdc/kdc.conf
   
   install -m 644 plugins/kdb/ldap/libkdb_ldap/kerberos.{ldif,schema} ${pkgdir}/usr/share/doc/${pkgname}/examples

   # Default configuration file
   install -dm 755 ${pkgdir}/etc
   install -pm 644 config-files/krb5.conf ${pkgdir}/etc/krb5.conf

   install -Dm644 ${srcdir}/${pkgname}-${pkgver}/NOTICE ${pkgdir}/usr/share/licenses/${pkgname}/LICENSE

   # install systemd units
   install -dm 755 ${pkgdir}/usr/lib/systemd/system
   install -m 644 ../../krb5-{kadmind.service,kdc.service,kpropd.service,kpropd@.service,kpropd.socket} \
      ${pkgdir}/usr/lib/systemd/system
}
